import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart';
import 'package:get/get.dart';
import 'package:untitled1/app/broker/modules/WebViewPage.dart';
import 'package:untitled1/app/login/PhoneCodePage.dart';
import 'package:untitled1/app/pay/showLockInfoDialog.dart';
import 'package:untitled1/app/pay/showLockInfoDialog2.dart';
import 'package:untitled1/app/res/myColors.dart';
import 'package:untitled1/app/utils/utilHttpUrl.dart';
import 'package:untitled1/app/utils/utilRouter.dart';
import 'package:untitled1/app/utils/utilScreen.dart';
import 'package:untitled1/app/widgets/TitleBar.dart';
import 'package:untitled1/app/widgets/button/MyElevatedButton.dart';
import 'package:untitled1/app/widgets/dialog/MyConfirmDialog.dart';

import '../broker/modules/home/AppHomePage.dart';
import '../broker/modules/home/DetailPage.dart';
import '../broker/modules/employer/EmployerDetailPage.dart';
import '../widgets/base_page/BaseStatefulPage.dart';
import '../widgets/dialog/MyConfirmCancelDialog.dart';
import '../widgets/input/CustomTextField.dart';
import '../widgets/toast/MyToast.dart';
import 'LoginPapgeController.dart';

class LoginPhonePapge extends BaseStatefulPage {
  var phone_number = '15311649002';

  LoginPhonePapge({super.key}) : super();

  @override
  BaseStatefulPageState<BaseStatefulPage> createState() =>
      _LoginPhonePapgeState();
}

class _LoginPhonePapgeState extends BaseStatefulPageState<LoginPhonePapge> {
  final LoginPapgeController controller = Get.put(
    LoginPapgeController(totalSeconds: 60),
  );

  late TextEditingController textController;

  @override
  void initState() {
    super.initState();
    textController = TextEditingController(text: widget.phone_number);
  }

  @override
  Widget buildPage(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      // appBar: TitleBar(title: "登录"),
      body: Container(
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        color: myColors.white,
        padding: EdgeInsets.only(left: 20, right: 20),
        child: Column(
          children: [
            SizedBox(height: 100),
            Container(
              alignment: Alignment(-1, 0),
              child: Text(
                "手机号快捷登录",
                style: TextStyle(
                  fontSize: 20,
                  color: myColors.c_191919,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ),
            Container(
              alignment: Alignment(-1, 0),
              child: Text(
                "欢迎来到家园科技",
                style: TextStyle(fontSize: 12, color: myColors.c_707070),
              ),
            ),
            SizedBox(height: 100),
            Container(
              height: 50,
              child: Stack(
                alignment: Alignment.centerLeft,
                children: [
                  TextField(
                    decoration: InputDecoration(
                      hintText: "请输入手机号",
                      hintStyle: TextStyle(
                        fontSize: 14,
                        color: myColors.c_B5B5B5,
                      ),
                      border: InputBorder.none,
                    ),
                  ),
                  Align(
                    alignment: Alignment.bottomCenter,
                    child: Divider(height: 1, color: myColors.c_D1D3D5),
                  ),
                ],
              ),
            ),
            Container(
              height: 50,
              child: Stack(
                alignment: Alignment.centerLeft,
                children: [
                  TextField(
                    decoration: InputDecoration(
                      hintText: "请输入验证码",
                      hintStyle: TextStyle(
                        fontSize: 14,
                        color: myColors.c_B5B5B5,
                      ),
                      border: InputBorder.none,
                    ),
                  ),
                  Align(
                    alignment: Alignment.bottomCenter,
                    child: Divider(height: 1, color: myColors.c_D1D3D5),
                  ),
                  Align(
                    alignment: Alignment.centerRight,
                    child: Obx(
                      () => TextButton(
                        onPressed:
                            controller.isCounting
                                ? null
                                : () {
                                  controller.startCountdown();
                                  // utilRouter.to(JingJiRenHomePage());
                                },
                        child: Text(
                          controller.isCounting
                              ? '${controller.remaining.value}秒后重试'
                              : '获取验证码',
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
            SizedBox(height: 20),
            Container(
              child: Row(
                children: [
                  Image.asset('assets/app/logo.png', height: 20, width: 20),
                  Container(
                    width: MediaQuery.of(context).size.width - 60,
                    child: getViewAgreement(),
                  ),
                ],
              ),
            ),
            SizedBox(height: 50),
            GestureDetector(
              onTap: () {
                Get.to(() => AppHomePage());
                // MyConfirmCancelDialog(context: context, content: getViewAgreement(),onConfirm: (){
                //   EmployerPageDialog.dialog_citySelect(context,(data)async{
                //       print(">]login data=${data}");
                //       utilRouter.back();
                //
                //         await Future.delayed(Duration(milliseconds: 300));
                //         Get.to(() => AppHomePage());
                //
                //     });
                // },onCancel: (){},);
                //直接在initState弹出是会报错的，因为页面还没有加载出来

              },
              child:  Container(
                  alignment: Alignment.center,
                  height: 50,
                  width: MediaQuery.of(context).size.width - 30,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(50),
                    gradient: LinearGradient(
                      colors: [myColors.c_F89596, myColors.c_FF4142],
                      begin: Alignment.centerLeft,
                      end: Alignment.centerRight,
                    ),
                  ),
                  child:Text("登录", style: TextStyle(color: myColors.white,fontSize: 14,fontWeight: FontWeight.bold)),

              ),
            )

          ],
        ),
      ),
    );
  }

  Widget getViewAgreement(){
    return RichText(
      textAlign: TextAlign.start,
      softWrap: true,
      overflow: TextOverflow.visible,
      text: TextSpan(
        text: '我已阅读并同意',
        style: TextStyle(color: Colors.black, fontSize: 12),
        children: [
          TextSpan(
            text: '《用户协议》',
            style: TextStyle(color: myColors.c_FF4142),
            recognizer:
            TapGestureRecognizer()
              ..onTap = () {
                // MyToast.show(context, "aaaa");
                utilRouter.to(WebViewPage(url: 'http://192.168.226.111:8889/vite#/jykjTest?version=1',webpageName: '用户协议'));
              },
          ),
          TextSpan(
            text: '，',
            style: TextStyle(color: Colors.black),
          ),
          TextSpan(
            text: '《隐私政策》',
            style: TextStyle(color: myColors.c_FF4142),
            recognizer:
            TapGestureRecognizer()
              ..onTap = () {
                utilRouter.to(WebViewPage(url: utilHttpUrl.ysxy,webpageName: '隐私政策'));
              },
          ),
          TextSpan(
            text: '及',
            style: TextStyle(color: Colors.black),
          ),
          TextSpan(
            text: '《第三方SDK类服务商说明》',
            style: TextStyle(color: myColors.c_FF4142),
            recognizer:
            TapGestureRecognizer()
              ..onTap = () {
                utilRouter.to(WebViewPage(url: utilHttpUrl.sfsdk,webpageName: '第三方SDK类服务商说明'));
              },
          ),
        ],
      ),
    );
}
}
